import type { DailyData } from '@/Interface/StoreInfoInterface'
import { create } from 'zustand'
import { persist, createJSONStorage } from 'zustand/middleware'
import { immer } from 'zustand/middleware/immer'

type DayState = {
  dayData: DailyData | null
  setDayData: (value: DailyData) => void
}

export const useDayStore = create<DayState>()(
  persist(
    immer((set) => ({
      dayData: null,
      setDayData: (value) =>
        set((status) => { status.dayData = value })
    })),
    {
      name: 'day-storage',
      storage: createJSONStorage(() => sessionStorage),
    }
  )
)